import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);
// 登录验证
export default new Vuex.Store({
    state: {
        user: false,
        userName:''
    },
    mutations: {
        // 登录
        login(state, user) {
            state.user = user;
            localStorage.setItem("userInfo", user);
        },
        // 退出
        logout(state, user) {
            state.user = "";
            localStorage.setItem("userInfo", "");
        },
        saveUserInfo(state,userName){
            state.userName = userName;
            sessionStorage.setItem("userName", userName);
        },
        getUserInfo(state){
            state.userName = sessionStorage.getItem("userName");
        },
        clear(state){
            state.user = false;
            state.userName = '';
            sessionStorage.clear();
        }
    }
})